<body>
    <link href="./Public/Admin/css/H-ui.min.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./Public/Admin/lib/layer/1.9.3/layer.js"></script>
	<link rel="stylesheet" href="./Public/Admin/lib/layer/1.9.3/skin/layer.css" id="layui_layer_skinlayercss">
<style type="text/css">
        .col-lg-10 {
            margin: 12px auto;
            float: none;
            overflow: auto;
        }

        .input-text, .select-box {
            border-color: #ccc;
        }

        .input-control {
            float: left;
            margin-right: 8px;
        }

        input {
            font-size: 24px;
            font-weight: bolder;
        }
		tfoot tr:first-child td{
			font-size:18px;
			font-weight:bold;
		}
		.border{
			border: #00c393 solid 1px;
			border-radius: 4px;
			height:auto;
			overflow: auto;
		}
		.nums{
			color:red;
			font-weight:bold;
			font-size:16px;
			margin-right:15px;
		}
		 body .demo-class .layui-layer-title{background:#333; color:#fff; border: none;font-size:20px;} body .demo-class .layui-layer-btn{border-top:1px solid #E9E7E7;padding:0;text-align:left;} body .demo-class .layui-layer-content{height:80px !important;font-size:30px;} body .demo-class .layui-layer-btn a{background:none;} body .demo-class .layui-layer-btn .layui-layer-btn1{background:none;} body .demo-class2 .layui-layer-title{background:#333; color:#fff; border: none;font-size:20px;} body .demo-class2 .layui-layer-btn{border-top:1px solid #E9E7E7;padding:0px;} body .demo-class2 .layui-layer-content
        {height:80px !important;font-size:30px;}
</style>

<div class="container">
    <div class="col-lg-10">
        <input class="input-text radius size-XL" id="saom" name="saom" type="text" placeholder="请扫描{:C('scanorder.lang_name')}"/>
        <span>*扫描完成后点击"提交"按钮，批量提交到服务器</span>
    </div>
    <div class="col-lg-10">
        <input id="sub" class="btn btn-success radius size-XL" type="button" value="确认"/>
		<input id="history" class="btn btn-success radius size-XL" type="button" onclick="window.parent.showTab('{:U('Outbound/pushorderlist',array('is_emergency'=>1))}','已出库列表')" value="已出库列表"/>
		<span style="float:right;margin-top:29px;color:red;display:none;">客户端<input type="checkbox" value="1" name="client" checked></span>
    </div>
	<div class='col-lg-10'>
        <table class="table border table-border">
            <tbody>
				<tr class="success">
					<td>序号</td>
					<td>面单编号</td>
					<td style="width:150px;">
						<span>总数：</span><span class="nums">0</span><input id="suball" class="btn btn-success radius size-XS" type="button" value="提交"/>
					</td>
				</tr>
			</tbody>
			<tfoot>
				
			</tfoot>
		</table>
    </div>
</div>
<script type="text/javascript">
	var reload=1;//刷新页面0：否1：是
	var nums = 0;
	function rend_tr(){
		autoindex=0;
		var mailno_list=localStorage.mailno;
		if(mailno_list.length>0){
			var arr=mailno_list.split(",");
			$.each(arr,function(key,val){
				autoindex++;
				if(reload==1){
					nums++;
				}
				$(".nums").text(autoindex);
				tr="<tr><td>"+autoindex+"</td><td>"+val+"</td><td></td></tr>";
				$(".border tfoot").prepend(tr);
			})
		}
	}
	if(localStorage.mailno==undefined){
		localStorage.mailno="";
	}else{
		rend_tr();
	}
	$(document).on('click','.delt',function(){
		var ttt=$(this).parents('tr').find('td').eq(1).text();
		$("tfoot").find('tr').remove();
		var mailno_list=localStorage.mailno;
		if(mailno_list.length>0){
			var arr=mailno_list.split(",");
			$.each(arr,function(key,val){
				if(val==ttt){
					arr.splice(key,1);
				}
				<!-- console.log(val+",,,"+ttt); -->
			})
			localStorage.mailno=arr.join(',');
		}
		reload=0;//刷新页面0：否1：是
		rend_tr();
	})
    $("#saom").focus();
    $(document).keydown(function (event) {
        $("#saom").focus();
    });
	$(document).mouseup(function (event) {
		$("#saom").focus();
    });
    
    $("#saom").keydown(function (event){
        if (event.keyCode == 13) {
			$("#sub").click();
        }
    });
	
	$("#sub").click(function(){
		//空判断-begin
		saom=myTrim($("#saom").val());
		if(saom==""){
			play_audio_file('failed');
            alerts('{:C("scanorder.lang_name")}号不能为空！');
			return false;
		}
		//空判断-begin
		//重复判断-begin
		mailno_list=localStorage.mailno;
		arr=mailno_list.split(",");
		for(i=0;i<arr.length;i++){
			if(saom==arr[i]){
				play_audio_file('duplicate');
				alerts('{:C("scanorder.lang_name")}号重复！');
				return false;
			}
		}
		//重复判断-end
		//客户端校检数据-begin
		var client=$('input[name=client]:checked').val();
		if(client=="1"){
			//提交检查数据库-begin
			var order_select="http://127.0.0.1:8089/order";
			$.ajax({
				type:"GET",
				url:order_select,
				data:{logisticsNo:saom},
				success: function(data){
					console.log(data);
					if(data.status==1){
						$.ajax({
							type:"GET",
							data:{logisticsNo:saom},
							url:"http://127.0.0.1:8089/submi",
							success:function(result){
								
							}
						})
						//已称重包裹表
						render(saom);
					}else{
						if(data.status==0){
							play_audio_file('failed');
						}
						if(data.status==2){
							play_audio_file('nothisorder');
						}
						if(data.status==3){
							play_audio_file('noweight');
						}
						<!-- if(data.status==4){ -->
							<!-- play_audio_file('noprint'); -->
						<!-- } -->
						if(data.status==5){
							play_audio_file('hasoutbound');
						}
						if(data.status==6){
							play_audio_file('sbz');
						}
						alerts(data.message);
						return false;
					}
				}
			});
			//提交检查数据库-end
		}else{
			render(saom);
		}
		//客户端校检数据-end
		
	});
	function render(saom){
		nums++;
		$(".nums").text(nums);
		tr="<tr><td>"+nums+"</td><td>"+saom+"</td><td></td></tr>";
		$("#saom").val("");
		$(".border tfoot").prepend(tr);
		if(localStorage.mailno.length==0){
			localStorage.mailno=saom;
		}else{
			localStorage.mailno+=","+saom;
		}
		play_audio_file('success');
	}
	$("#suball").click(function(){
		if(localStorage.mailno==""){
			 alerts('没有数据');
			return false;
		}
		$.ajax({
			type:"POST",
			data:{mailNo:localStorage.mailno},
			url:"{:U('Outbound/outbount_batch')}",
			success:function(data){
				if(data.status==1){	//成功
					play_audio_file('success');
					localStorage.mailno="";
					layer.msg("正在刷新...",function(){
						window.location.reload();
					});
				}else{
					if(data.status==0){
						play_audio_file('failed');
						layer.msg(data.message);
					}
					if(data.status==2){
						play_audio_file('nothisorder');
						layer.msg(data.message);
					}
					if(data.status==3){
						play_audio_file('noweight');
						layer.msg(data.message);
					}
					if(data.status==5){
						play_audio_file('hasoutbound');
						layer.msg(data.message);
					}
					if(data.status==6){
						play_audio_file('sbz');
						layer.msg(data.message);
					}
					tr=$(".border tfoot").find('tr');
					count=tr.length;
					for(i=0;i<count;i++){
						if(data.mailNo==tr.eq(i).find('td').eq(1).text()){
							tr.eq(i).find('td').eq(2).text(data.message);
							tr.eq(i).find('td').eq(2).append("&nbsp;&nbsp;<span style='font-size:12px;cursor:pointer;' class='delt'>删除</span>");
							tr.eq(i).css('background','red');
							tr.eq(i).find('td').css("color","#fff").css("font-size","16px");
							//滚动-begin
							var divtop=tr.eq(i).offset().top;
							var scrollTop=$(window).scrollTop();
							if((scrollTop+70)!=divtop){
								$('html,body').animate({scrollTop: divtop-120+'px'},400);
							}
							//滚动-end
							return false;
						}
					}
				}
			}
		})
	});
	
	function play_audio_file(filename){
        var url = "http://127.0.0.1:8089";
        if($("audio").length == 0){
            $("body").append($("<audio src='' autoplay></audio>"));
        }
        $("audio").attr('src', url + '/voice/'+filename+'.wav');
    }
	function myTrim(str){
		return str.replace(/(^\s*)|(\s*$)/g, "");
	}
	function alerts(msg){
        var index = layer.open({
            type: 0,
            title: '系统提示',
            content: msg,
            shift: 2,
            btn: ['知道了'],
            time: 1200,
            offset: '120px',
            yes:function () {
                layer.close(index);
            }
        });
        $("#saom").prop("value", '');
		$("#saom").focus();
    }
</script>
</body>
